
#include "ObserverCenter.h"

using namespace npObserver;


//other constructors
void ObserverCenter::insertObserver(weak_ptr<Observer> observer) throw()
{
    if (shared_ptr<Observer> obs = observer.lock())
    {
        this->observers.push_back(observer);
    }
}

void ObserverCenter::removeObserver(weak_ptr<Observer> observer) throw()
{
    if (shared_ptr<Observer> obs = observer.lock())
    {
        for (auto i = this->observers.begin(); i != this->observers.end(); i++)
        {
            if (shared_ptr<Observer> iobs = i->lock())
            {
                if (obs.get() == iobs.get())
                {
                    this->observers.erase(i);
                    return;
                }
            }
        }
    }
}

void ObserverCenter::notify() throw()
{
    for (auto i = this->observers.begin(); i != this->observers.end(); i++)
    {
        if (shared_ptr<Observer> obs = i->lock())
        {
            obs->notify();
        }
    }
}

//public methods

//protected methods

//private methods

//static part

//others
